package com.zzzzzz.oms.vehicle;

import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.validation.ConstraintViolationException;
import javax.validation.Validator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.zzzzzz.core.datagrid.BaseData;
import com.zzzzzz.plugins.shiro.I;
import com.zzzzzz.utils.BeanValidators;
import com.zzzzzz.utils.DateTimeUtils;

@Service
public class VehicleService {
	
	@Resource
	public VehicleDao vehicleDao;
	
	@Resource
	public Validator validator;
	
	// 增加、修改
	@Transactional
	public int save(Vehicle vehicle, I i) {
		vehicle.setUpdDt(new Date());
		vehicle.setUpdBy(i.getId());
		if (vehicle.getId() == null) {
			vehicle.setAddDt(new Date());
			vehicle.setAddBy(i.getId());
			vehicleDao.add(vehicle);
		} else {
			vehicleDao.updById(vehicle);
		}
		return 1;
	}
	
	// 通过cd查找Vehicle
	public Vehicle getVehicleByCd(String cd) {
		Map<String,Vehicle> allVehicleMap=vehicleDao.getAllVehicleMap();
		Vehicle vehicle=allVehicleMap.get(cd);
		return vehicle;
	}
	
	private static final Logger logger = LoggerFactory.getLogger(Vehicle.class);
}
